package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.extension.api.R;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: 🐱🐱🐱
 * @Date: 2025/8/16 12:46
 * @Description:
 **/
@Api(tags = "商品基础属性接口")
@RestController
@RequestMapping("/admin/product")
public class BaseManageController {

    @Resource
    private ManageService manageService;

    /**
     * 查询一级分类接口
     * @return
     */
    @GetMapping("/getCategory1")
    private Result getCategory1(){
       List<BaseCategory1> category1List = manageService.getCategory1();
       return Result.ok(category1List);
    }

    /**
     * 查询二级分类接口
     * @return
     */
    @GetMapping("getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable("category1Id") String category1Id){
        List<BaseCategory2> category2List = manageService.getCategory2(category1Id);
        return Result.ok(category2List);
    }

    /**
     * 查询三级分类接口
     * @return
     */
    @GetMapping("getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable("category2Id") String category2Id){
        List<BaseCategory3> category3List = manageService.getCategory3(category2Id);
        return Result.ok(category3List);
    }

    /**
     * 根据分类Id 获取平台属性数据
     */
    @GetMapping("attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result attrInfoList(@PathVariable("category1Id") String category1Id,
                               @PathVariable("category2Id") String category2Id,
                               @PathVariable("category3Id") String category3Id){
       List<BaseAttrInfo> attrInfoList = manageService.attrInfoList(category1Id,category2Id,category3Id);
        return Result.ok(attrInfoList);
    }

    /**
     * 添加平台属性和添加平台属性值
     * @param baseAttrInfo
     * @return
     */
    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
         manageService.saveAttrInfo(baseAttrInfo);
         return Result.ok();
    }

    /**
     * 根据id查询平台属性回显
     * @param attrId
     * @return
     */
    @GetMapping("getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable("attrId") Long attrId){
      BaseAttrInfo baseAttrInfo =  manageService.getAttrInfo(attrId);
        List<BaseAttrValue> attrValueList = baseAttrInfo.getAttrValueList();
        return Result.ok(attrValueList);
    }

}
